import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'profileProvider.dart';
import 'package:flutter_module/tabbar/routers/application.dart';
import 'package:flutter_module/tabbar/routers/Routes.dart';
import 'package:fluro/fluro.dart';

class ProfileScreen extends StatelessWidget {  

  @override
  Widget build(BuildContext context) {

    // final double topPadding = MediaQuery.of(context).padding.top;

    // Provider.of<ProfileProvider>(context).headerHeightChange(topPadding);

    return Scaffold(
      backgroundColor: Color.fromRGBO(235, 239, 244, 1),
      body: CustomScrollView(
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: _profileHeaderWidget(context),
          ),
          SliverList(
            delegate: SliverChildListDelegate([
              _profileItemWidget(context,'images/profile_changePassword.png','修改密码',true),
              _profileItemWidget(context,'images/profile_about.png','关于云盯',false),
              _profileItemWidget(context,'images/profile_feedback.png','意见反馈',false),
              _profileItemWidget(context,'images/profile_logout.png','退出登录',true),
            ]),
          ),
        ],
      )
    );
  }


  Widget _profileHeaderWidget(context){
    final double topPadding = MediaQuery.of(context).padding.top;
    return Consumer<ProfileProvider>(builder: (context,ProfileProvider profileP,child){
      profileP.headerHeightChange(topPadding);
      return Container(
        decoration: BoxDecoration(color: Color.fromRGBO(46, 137, 250, 1)),
        height: 130.0 + profileP.headerHeight,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.end,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    SizedBox(width: 20),
                    CircleAvatar(
                      radius: 35,
                      backgroundImage: NetworkImage('https://pic2.zhimg.com/v2-639b49f2f6578eabddc458b84eb3c6a1.jpg'),
                    ),
                    SizedBox(width: 20,),
                    Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text('张三丰',textAlign: TextAlign.left,style: TextStyle(color: Colors.white),),
                        SizedBox(height: 10,),
                        Text('成都云盯科技-运营总监',textAlign: TextAlign.left,style: TextStyle(color: Colors.white)),
                      ],
                    ),
                  ],
                ),
                Padding(
                  padding: EdgeInsets.only(right: 15),
                  child: Image.asset('images/common_arrow_lucency_right.png'),
                )
              ],
            ),
            SizedBox(height: 30)
          ],
        )
      );
    });

  }

  Widget _profileItemWidget(BuildContext context,String imageName,String title,bool cuttingLine){

    return InkWell(
      onTap: (){
        print('退出登录');
        Application.router.navigateTo(context, Routes.login,transition: TransitionType.inFromBottom,clearStack: true);
      },
      child: Column(
        children: <Widget>[
          Offstage(
            offstage: !cuttingLine,
            child: Container(height: 10,color: Color.fromRGBO(235, 239, 244, 1),)
          ),
          Container(
            height: 54,
            color: Colors.white,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    SizedBox(width: 20),
                    Image.asset(imageName),
                    SizedBox(width: 20),
                    Text(title)
                  ],
                ),
                Padding(
                  padding: EdgeInsets.only(right: 15),
                  child: Image.asset('images/common_arrow_gray_right.png'),
                )
              ],
            ),
          ),
          Container(height: 1,color: Color.fromRGBO(235, 239, 244, 1),)
        ],
      ),
    );

  }
}